package asteroids.expressions;

import java.util.*;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.Ship;
import asteroids.types.Type;

public class VariableExpression extends BasicExpression {
	
	private String name;

	public VariableExpression(int line, int column, String name) {
		super(line, column);
		this.name = name;
	}

	@Basic
	public String getName() {
		return name;
	}

	@Override
	public Type evaluate(Ship ship, Map<String, Type> globals) {
		return globals.get(getName());
	}
	
	@Override
	public List<String> getTypeCheckErrorsExpressions(List<String> typeErrors, Map<String, Type> globals) {
		if(! globals.containsKey(getName()))
			typeErrors.add("Line: " + getLine() + " Column: " + getColumn() + " - There is no global variable with variable name '"+ getName() +"'.");
		return typeErrors;
	}
	
	@Override
	public String toString() {
		return getName();
	}

}
